import { Client } from "./mod.ts";

/**
 * DeployKey represents a deploy key of repository
 */
export interface DeployKey {
  id: number;
  key: string;
  url: string;
  title: string;
  created_at: string;
  read_only: boolean;
}

/**
 * CreateKeyOption represents options for creating a deploy key
 */
export interface CreateKeyOption {
  title: string;
  key: string;
}

/**
 * Deploy Key API endpoints
 */
export class DeployKeyAPI {
  constructor(private client: Client) {}

  /**
   * List deploy keys of a repository
   */
  async listDeployKeys(owner: string, repo: string): Promise<DeployKey[]> {
    return await this.client.doRequest<DeployKey[]>(
      "GET", 
      `/repos/${owner}/${repo}/keys`
    );
  }

  /**
   * Get a deploy key of a repository
   */
  async getDeployKey(owner: string, repo: string, keyID: number): Promise<DeployKey> {
    return await this.client.doRequest<DeployKey>(
      "GET", 
      `/repos/${owner}/${repo}/keys/${keyID}`
    );
  }

  /**
   * Create a deploy key for a repository
   */
  async createDeployKey(owner: string, repo: string, options: CreateKeyOption): Promise<DeployKey> {
    return await this.client.doRequest<DeployKey>(
      "POST", 
      `/repos/${owner}/${repo}/keys`, 
      { "Content-Type": "application/json" },
      options
    );
  }

  /**
   * Delete a deploy key from a repository
   */
  async deleteDeployKey(owner: string, repo: string, keyID: number): Promise<void> {
    await this.client.doRequest<void>(
      "DELETE", 
      `/repos/${owner}/${repo}/keys/${keyID}`
    );
  }
} 